<?php
class Bank_model extends CI_Model{

	function   __construct() {
        parent::__construct();
    }

   //page
	private $tbl = 'bank';

	function selectAll()
	{
		return $this->db->get($this->tbl)->result();
	}
		
	function get_list_data($limit = 10, $offset = 0) 
  	{
		$this->db->limit($limit, $offset);
  		$this->db->order_by('strnama_bank','asc');
		return $this->db->get($this->tbl,$limit,$offset);
  	}
	
	function countData() 
	{   
	  	return $this->db->count_all($this->tbl);
  	}
//end page

    function getBank(){

	   $query = $this->db->query("SELECT *  FROM bank
               ORDER BY intid_bank ASC");
	   return $query->result();
    }

    function insert($data){
	$data = array(
            'strnama_bank' => $this->input->post('strnama_bank'));
        $this->db->insert('bank', $data);
	}

   function delete($idbank){
       $this->db->where('intid_bank', $idbank);
       $this->db->delete('bank');
    }

    function select($idbank){
       $query = $this->db->query("select * from bank where intid_bank = $idbank");
	   return $query->result();
    }

	function update($idbank){
            $data = array(
            'strnama_bank' => $this->input->post('strnama_bank'));
            $this->db->where('intid_bank', $idbank);
            $this->db->update('bank',$data);
    }
    //TEST search
    function search($key)
	{
		$this->db->like('strnama_bank',$key);
		return $this->db->get($this->tbl);
	}

    //end test
  //test paging
  function getAllGrid($start,$limit,$sidx,$sord,$where){
//    $this->db->select('intid_bank,strnama_bank'); -->cara 1
//    $this->db->limit($limit);
//    if($where != NULL)$this->db->where($where,NULL,FALSE);
//    $this->db->order_by($sidx,$sord);
//    $query = $this->db->get('bank',$limit,$start);
//
//    return $query->result();
      //cara 2
      $query = $this->db->query("SELECT intid_bank, strnama_bank
          FROM bank ".$where." ORDER BY $sidx $sord LIMIT $start , $limit");
      return $query->result();
  }

  function get($intid_bank){
    $query = $this->db->getwhere('bank',array('intid_bank'=>$intid_bank));
    return $query->row_array();
  }
//end of test paging
}
?>
